﻿using Business.Base.Model;
using Component;
using Pumptester.ExperimentForms.Base;


namespace Pumptester.ExperimentForms.Npsh
{
    public class NpshChartcs : IChartDrawer
    {
        public void DrawChart(BaseChartData chartData, UserChart chart)
        {
            CentrifugalPumpPerfChartData chartDatainfo = (CentrifugalPumpPerfChartData)chartData;
            Component.Axis xAxis = new Component.Axis();
            xAxis.Name = "流量";
            xAxis.MaxValue = chartDatainfo.MaxXQAxis;
            xAxis.MinValue = chartDatainfo.MinXQAxis;
            xAxis.SegCount = chartDatainfo.XUnitCount;

            Component.Axis yAxis = new Component.Axis();
            yAxis.Name = "扬程";
            yAxis.MaxValue = chartDatainfo.MaxYHAxis;
            yAxis.MinValue = chartDatainfo.MinYHAxis;
            yAxis.SegCount = chartDatainfo.YUnitCount;


            Component.Axis ySencodAxis = new Component.Axis();
            ySencodAxis.Name = "功率";
            ySencodAxis.MaxValue = chartDatainfo.MaxYPAxis;
            ySencodAxis.MinValue = chartDatainfo.MinYPAxis;

            Component.Axis yThirdAxis = new Component.Axis();
            yThirdAxis.Name = "效率";
            yThirdAxis.MaxValue = chartDatainfo.MaxYEAxis;
            yThirdAxis.MinValue = chartDatainfo.MinYEAxis;


            Coordinate coordinate = new Coordinate();
            coordinate.XAxis = xAxis;
            coordinate.YAxis = yAxis;
            coordinate.TextBrush = new SolidBrush(Color.White);
            coordinate.AxisPen = new Pen(Color.White);
            coordinate.CurvePen = new Pen(new SolidBrush(Color.Blue), 2);
            //coordinate.PointBrush = new SolidBrush(Color.Blue);
            coordinate.PointBrush = new SolidBrush(Color.Yellow);

            Coordinate secondCoordinate = new Coordinate();
            secondCoordinate.XAxis = xAxis;
            secondCoordinate.YAxis = ySencodAxis;
            secondCoordinate.CurvePen = new Pen(new SolidBrush(Color.Gray), 2);
            secondCoordinate.PointBrush = new SolidBrush(Color.Orange);

            Coordinate thirdCoordinate = new Coordinate();
            thirdCoordinate.XAxis = xAxis;
            thirdCoordinate.YAxis = yThirdAxis;
            thirdCoordinate.CurvePen = new Pen(new SolidBrush(Color.Silver), 2);
            thirdCoordinate.PointBrush = new SolidBrush(Color.Red);

            SolidBrush defaultAuxiliaryAxisPointBrush = new SolidBrush(Color.White);
            coordinate.AuxiliaryAxisPointBrush = secondCoordinate.AuxiliaryAxisPointBrush = thirdCoordinate.AuxiliaryAxisPointBrush = defaultAuxiliaryAxisPointBrush;
            thirdCoordinate.TextBrush = secondCoordinate.TextBrush = coordinate.TextBrush = new SolidBrush(Color.White);
            thirdCoordinate.AxisPen = secondCoordinate.AxisPen = coordinate.AxisPen = new Pen(Color.White);


            for (int i = 0; i < chartDatainfo.InputPoints.Count; i++)
            {
                double q = chartDatainfo.InputPoints[i][0];
                double h = chartDatainfo.InputPoints[i][1];
                double p = chartDatainfo.InputPoints[i][2];
                double e = chartDatainfo.InputPoints[i][3];
                coordinate.Points.Add(new Component.Point(q, h));
                secondCoordinate.Points.Add(new Component.Point(q, p));
                thirdCoordinate.Points.Add(new Component.Point(q, e));

            }



            int pointCount = chartDatainfo.DrawList.Count;
            List<Component.Point> firstPoints = new List<Component.Point>();
            List<Component.Point> secondPoints = new List<Component.Point>();
            List<Component.Point> thirdPoints = new List<Component.Point>();

            for (int i = 0; i < pointCount; i++)
            {
                double[] data = chartDatainfo.DrawList[i];
                double x = data[0];
                double[] qePoints = new double[] { x, data[3] };
                double[] qhPoints = new double[] { x, data[1] };
                double[] qpPoints = new double[] { x, data[2] };

                Component.Point p1 = new Component.Point(qhPoints[0], qhPoints[1]);
                firstPoints.Add(p1);

                Component.Point p2 = new Component.Point(qpPoints[0], qpPoints[1]);
                secondPoints.Add(p2);

                Component.Point p3 = new Component.Point(qePoints[0], qePoints[1]);
                thirdPoints.Add(p3);



            }
            Curve firstCurve = new Curve(firstPoints);

            Curve secondCurve = new Curve(secondPoints);
            Curve thirdCurve = new Curve(thirdPoints);

            coordinate.Curves.Add(firstCurve);
            secondCoordinate.Curves.Add(secondCurve);

            thirdCoordinate.Curves.Add(thirdCurve);
            chart.FirstCoordinate = coordinate;
            chart.SecondCoordinate = secondCoordinate;
            chart.ThirdCoordinate = thirdCoordinate;

            chart.Refresh();
        }
    }
}
